<?php

namespace addons\travel\listener\order;

use addons\sum\exception\Exception;
use addons\travel\model\Goods as GoodsModel;
use think\Db;

/**
 * 订单失效
 */
class Invalid
{
    // 订单取消后行为
    public function orderCancelAfter(&$params)
    {
        $order = $params['order'];

        $this->invalid($order, 'cancel');

        return $order;
    }


    // 订单关闭后行为
    public function orderCloseAfter(&$params)
    {
        $order = $params['order'];
        $this->invalid($order, 'close');
    }

    // 订单取消或关闭返还
    private function invalid($order, $type) {
        // 恢复库存
        if($order['goods_type']=='house'){
            $goods_or_home_id=$order['goods_id_home'];
        }else{
            $goods_or_home_id=$order['goods_id'];
        }
        GoodsModel::where('id',$goods_or_home_id)->where('is_stock',1)->setInc('stock');
        return $order;

    }
}
